package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 04
 * Time:9:46
 */

/***
 * 1.删除有序数组中的重复项,原地删除，使得每个元素只出现一次，返回删除后数组的新长度
 */
public class Test1 {
    public int removeDuplicates(int[] nums) {
        if(nums.length < 2){
            return nums.length;
        }
        int left = 0;
        for(int right = 1;right < nums.length;right ++)  {
            if(nums[left] != nums[right]){
                nums[++left] = nums[right];
            }
        }
        return left + 1;
    }

}
